using Uantek.Device.Communication.Models;

namespace Uantek.Device.Communication.Services.Interfaces
{
    /// <summary>
    /// 数据收集服务接口
    /// </summary>
    public interface IDataCollectionService
    {
        /// <summary>
        /// 开始数据收集
        /// </summary>
        /// <param name="deviceId">设备ID</param>
        /// <param name="collectionInterval">收集间隔（毫秒）</param>
        /// <returns>操作结果</returns>
        Task<CommunicationResult> StartCollectionAsync(string deviceId, int collectionInterval = 1000);

        /// <summary>
        /// 停止数据收集
        /// </summary>
        /// <param name="deviceId">设备ID</param>
        /// <returns>操作结果</returns>
        Task<CommunicationResult> StopCollectionAsync(string deviceId);

        /// <summary>
        /// 暂停数据收集
        /// </summary>
        /// <param name="deviceId">设备ID</param>
        /// <returns>操作结果</returns>
        Task<CommunicationResult> PauseCollectionAsync(string deviceId);

        /// <summary>
        /// 恢复数据收集
        /// </summary>
        /// <param name="deviceId">设备ID</param>
        /// <returns>操作结果</returns>
        Task<CommunicationResult> ResumeCollectionAsync(string deviceId);

        /// <summary>
        /// 设置数据收集配置
        /// </summary>
        /// <param name="deviceId">设备ID</param>
        /// <param name="configuration">收集配置</param>
        /// <returns>操作结果</returns>
        Task<CommunicationResult> SetCollectionConfigurationAsync(string deviceId, Dictionary<string, object> configuration);

        /// <summary>
        /// 获取设备的历史数据
        /// </summary>
        /// <param name="deviceId">设备ID</param>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <returns>历史数据列表</returns>
        Task<IEnumerable<DeviceDataModel>> GetHistoricalDataAsync(string deviceId, DateTime startTime, DateTime endTime);

        /// <summary>
        /// 获取设备的实时数据
        /// </summary>
        /// <param name="deviceId">设备ID</param>
        /// <returns>实时数据</returns>
        Task<DeviceDataModel?> GetRealTimeDataAsync(string deviceId);

        /// <summary>
        /// 导出设备数据
        /// </summary>
        /// <param name="deviceId">设备ID</param>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <param name="format">导出格式（JSON、CSV等）</param>
        /// <returns>导出结果</returns>
        Task<CommunicationResult<byte[]>> ExportDataAsync(string deviceId, DateTime startTime, DateTime endTime, string format = "JSON");

        /// <summary>
        /// 数据收集事件
        /// </summary>
        event EventHandler<DeviceDataModel>? DataCollected;

        /// <summary>
        /// 数据收集错误事件
        /// </summary>
        event EventHandler<(string DeviceId, Exception Error)>? CollectionError;
    }
}